/*
 * 
 * Version 1.00
 * 
 * Created on 2007-6-4
 * Encoding GB2312
 */
package net.comm.friend.service.impl;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.List;
import java.util.Vector;

import net.comm.check.service.impl.JifenServiceImpl;
import net.comm.common.GlbFinal;
import net.comm.common.ReturnMessage;
import net.comm.common.common;


import net.comm.friend.bean.BaseFriend;
import net.comm.friend.db.DbFriendService;
import net.comm.friend.db.FriendServiceSqlMysql;
import net.comm.friend.web.form.BlacklistForm;
import net.comm.friend.web.form.FriendForm;
import net.comm.oper.service.impl.OperLogServiceImpl;
import net.comm.oper.web.form.OperLogForm;
import net.comm.page.PageCtr;
import net.comm.param.service.impl.SequenceMgr;

import net.comm.tags.JstlFun;
import net.comm.user.service.impl.UserSysinfoServiceImpl;
import net.comm.user.service.impl.UsersServiceImpl;
import net.comm.user.web.form.UserSysinfoForm;
import net.comm.user.web.form.UsersForm;
import net.comm.util.DatetimeUtil;
import net.comm.util.DbcpPool;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.log4j.Logger;
import org.sakaiproject.db.impl.BasicSqlService;


/**
 *
 * @author hcgong(hcgong@sina.com)
 * @version 1.0
 * @date 2007-6-4
 */
public class FriendServiceImpl {

	static Logger logger = Logger.getLogger(FriendServiceImpl.class.getName());

	/**
	 * 
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#list(net.swift.module.other.ExaQueryBean, net.swift.common.ReturnMessage)
	 */
	public List list(FriendForm theForm,  ReturnMessage msg) 
	{
		List list = null;

		Connection cn = null;

		try
		{
			cn = DbcpPool.getConnection();
			
			FriendServiceSqlMysql servSql = new FriendServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();


			//取得FORM中传入的查询参数
			Object[] fields1 = new Object[1];
			fields1[0] = theForm.getQryUserID();

			/*
			 * 获得查询SQL语句
			 */
			String sql = servSql.getCountSql2();
			/**
			 * 根据SQL执行结果计算分页相关信息
			 */
			PageCtr page = theForm.getPage();
			page.setTotalNum(bSqlServ.dbCount(cn, sql, fields1));
			page.caculate();

			//取得FORM中传入的查询参数
			Object[] fields = new Object[3];
			
			
			fields[0] = theForm.getUserID();
			fields[1] = page.getPos()-1;
			fields[2] = page.getPageSize();
			
			sql = servSql.getRecbyPageSql();

			list = bSqlServ.dbRead(cn, sql, fields, new DbFriendService());
			
		    DbcpPool.returnConnection(cn);
		    
		} catch(Exception ex) 
		{
			/**
			 * 记录相关日志
			 */
			logger.error(ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
			
		} finally {
			DbcpPool.returnConnection(cn);
		}		
		
		return list;
	}

	/**
	 * 返回根据会员ID查询的会员好友
	 */
	public List list(int  userID) 
	{
		List list = null;
		Connection cn = null;

		try
		{
			cn = DbcpPool.getConnection();
			
			//取得FORM中传入的查询参数
			Object[] fields = new Object[1];
			
			fields[0] = userID;			

			FriendServiceSqlMysql servSql = new FriendServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();

			/*
			 * 获得查询SQL语句
			 */
			String sql = servSql.getByUserIDSql();
									
			list = bSqlServ.dbRead(cn, sql, fields, new DbFriendService());
									
		    DbcpPool.returnConnection(cn);
		    
		} catch(Exception ex) 
		{
			/**
			 * 记录相关日志
			 */
			logger.error(ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}		
			
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return list;
	}
	/**
	 * 
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#list(net.swift.module.other.ExaQueryBean, net.swift.common.ReturnMessage)
	 */
	public List adlist(FriendForm theForm,  ReturnMessage msg) 
	{
		List list = new Vector();

		Connection cn = null;
		Statement stmt=null;
		ResultSet rs=null;
		try
		{
			cn = DbcpPool.getConnection();
			
			FriendServiceSqlMysql servSql = new FriendServiceSqlMysql();
			
			StringBuffer sb = new StringBuffer(" where 1=1 ");
			
			if(theForm.getQryUserID() > 0){
				
				sb.append(" and UserID = ");
				sb.append(theForm.getQryUserID());
				sb.append(" ");
			}
			
			if(theForm.getQryFriendID() > 0){
				
				sb.append(" and FriendID = ");
				sb.append(theForm.getQryFriendID());
				sb.append(" ");
			}
			
			if(theForm.getQryTeamID() > 0){
				
				sb.append(" and TeamID = ");
				sb.append(theForm.getQryTeamID());
				sb.append(" ");
			}
			
			//查询记录数
			stmt = cn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,ResultSet.CONCUR_READ_ONLY);
			String sql = servSql.getCountSql1();

			logger.debug(sql+sb.toString());
			
			rs=stmt.executeQuery(sql+sb.toString());
			int nRows = 0;
			if (rs.next())
	           nRows = rs.getInt("COUNT");
			else
			{
	            rs.close();
	            stmt.close();
	            DbcpPool.returnConnection(cn);
			    return list;
			}
			/**
			 * 根据SQL执行结果计算分页相关信息
			 */
			PageCtr page = theForm.getPage();
			page.setTotalNum(nRows);
			page.caculate();
			
			sb.append(" limit ");
			sb.append(page.getPos()-1);
			sb.append(", ");
			sb.append(page.getPageSize());
			
			 //取记录
			 sql = servSql.getRecSql();
			 logger.debug(sql+sb.toString());
			 
			 DbFriendService dbservice = new DbFriendService();
			 
			 rs=stmt.executeQuery(sql+sb.toString());
			 while (rs.next())
			 {
				try
				{
					Object obj = dbservice.readSqlResultRecord(rs);
					if (obj != null) list.add(obj);
				}
				catch (Throwable t)
				{
					logger.error(t.getMessage());
				}		
			 }
			 rs.close();
			 stmt.close();
		     DbcpPool.returnConnection(cn);

		} catch(Exception ex) 
		{
			/**
			 * 记录相关日志
			 */
			logger.error(ex.getMessage());
			try {
				if (rs != null)
					rs.close();
				if (stmt != null)
					stmt.close();
				DbcpPool.returnConnection(cn);
			} catch (Exception ex1) {
				ex1.printStackTrace();
			}			
	    }finally {
			try {
				if (rs != null)
					rs.close();
				if (stmt != null)
					stmt.close();
			} catch (Exception ex) {
				ex.printStackTrace();
			}			
			DbcpPool.returnConnection(cn);
		}		
		return list;
	}	
	
	/**
	 * 判断是否是好友返回根据会员ID查询的会员好友
	 */
	public boolean isFriend(int  userID, int friend) 
	{
		Connection cn = null;
		boolean isFrend = false;
		try
		{
			cn = DbcpPool.getConnection();
			
			isFrend = isFriend(cn, userID, friend);
			
		    DbcpPool.returnConnection(cn);
			return isFrend;						
		    
		} catch(Exception ex) 
		{
			/**
			 * 记录相关日志
			 */
			logger.error(ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}		
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return isFrend;						
	}
	/**
	 * 判断是否是好友返回根据会员ID查询的会员好友
	 */
	public boolean isFriend(Connection cn, int  userID, int friend) 
	{
		boolean isFrend = false;
		try
		{
			
			//取得FORM中传入的查询参数
			Object[] fields = new Object[2];
			
			fields[0] = userID;			
			fields[1] = friend;			

			FriendServiceSqlMysql servSql = new FriendServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();

			/*
			 * 获得查询SQL语句
			 */
			String sql = servSql.getIsUserIDFriendSql();
									
			List list = bSqlServ.dbRead(cn, sql, fields, new DbFriendService());
			
			if(list.size() == 0){
				
//				DbcpPool.rollBackTran(cn);
//				DbcpPool.closeTran(cn);
//			    DbcpPool.returnConnection(cn);
				return isFrend;
			}
		    isFrend = true;
			return isFrend;						
		    
		} catch(Exception ex) 
		{
			/**
			 * 记录相关日志
			 */
			logger.error(ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}		
			
		}
		
		return isFrend;						
	}	
	/**
	 * @see net.IUserbasicService.module.other.IUserService
	 * 		#get(net.swift.db.tab_paramnostro, net.swift.common.ReturnMessage)
	 */
	public void get(FriendForm theForm, ReturnMessage msg) 
	{
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			List list = null;

			//取得FORM中传入的查询参数
			Object[] fields = new Object[1];
			
			fields[0] = theForm.getSeqID();			
			
			FriendServiceSqlMysql servSql = new FriendServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();
			
			String sql = servSql.getbykeySql();			
					
			list = bSqlServ.dbRead(cn, sql, fields, new DbFriendService());
			
			if(list.size() ==0){
				common.setAppFailMsg(msg , " 取记录失败，请检查！");
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;				
			}
			
			BaseFriend base = (BaseFriend)list.get(0);
				
			BeanUtils.copyProperties(theForm, base);

			DbcpPool.returnConnection(cn);
			return;
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about invite" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return ;
	}

	/**
	 * 添加会员好友到表中
	 * @see net.IUserbasicService.module.other.IUserService#add(net.swift.common.ReturnMessage)
	 */
	public void add( FriendForm theForm, ReturnMessage msg) 
	{
	
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			DbcpPool.beginTran(cn);
			
			add(cn, theForm, msg);
			if(msg.getErrCode() != 0){
				return;
			}
			
			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);
			DbcpPool.returnConnection(cn);			

		} catch(Exception ex) 
		{
			common.setAppFailMsg(msg , " 添加好友失败！");
			logger.error("System error , param get about operlog" + ex);
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		}finally {
			DbcpPool.returnConnection(cn);
		}
		
		return ;
	}
	/**
	 * 添加会员好友到表中
	 * @see net.IUserbasicService.module.other.IUserService#add(net.swift.common.ReturnMessage)
	 */
	public void add(Connection cn, FriendForm theForm, ReturnMessage msg) 
	{
	
		try
		{
			//判断是否在黑名单
			BlacklistServiceImpl blackservice = new BlacklistServiceImpl();
			if(blackservice.isBlack(cn, theForm.getUserID(), theForm.getFriendID())){
				
				common.setAppFailMsg(msg , " 对方在您的黑名单中，不能成为好友！");
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;				
			}
			
			FriendServiceSqlMysql servSql = new FriendServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();

			Object[] fields2 = new Object[2];
			
			fields2[0] = theForm.getUserID();				
			fields2[1] = theForm.getFriendID();				
			
			String sql = servSql.getByUserIDFriendSql();

			//判断是否已经是好友
			List list = bSqlServ.dbRead(cn, sql, fields2, new DbFriendService());
			
			if(list.size() > 0){
				return;				
			}	
			sql = servSql.getInsertSql();
			
			//取得FORM中传入的查询参数
			Object[] fields = new Object[6];
			
			theForm.setSeqID(SequenceMgr.generateSeq(GlbFinal.SEQ_INITDATE, GlbFinal.SEQ_FRIENDID));			
			
			fields[0] = theForm.getSeqID();			
			fields[1] = theForm.getUserID();
			fields[2] = theForm.getFriendID();
			fields[3] = theForm.getTeamID();
			fields[4] = GlbFinal.STS_NORMAL;
			fields[5] = DatetimeUtil.getDatetime();
			
			boolean  res = bSqlServ.dbWrite(cn, sql, fields);
			if(!res){
				common.setAppFailMsg(msg , " 添加好友失败！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return ;
			}

			fields[0] = SequenceMgr.generateSeq(GlbFinal.SEQ_INITDATE, GlbFinal.SEQ_FRIENDID);			
			fields[1] = theForm.getFriendID();
			fields[2] = theForm.getUserID();
			fields[3] = theForm.getTeamID();
			fields[4] = GlbFinal.STS_NORMAL;
			fields[5] = DatetimeUtil.getDatetime();
			
			res = bSqlServ.dbWrite(cn, sql, fields);
			if(!res){
				common.setAppFailMsg(msg , " 添加好友失败！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return ;
			}
			
			UsersForm userForm = new UsersForm();
			userForm.setUserID(theForm.getUserID());
			
			UsersServiceImpl userservice = new UsersServiceImpl();
			userservice.get(userForm, msg);
			if(msg.getErrCode() !=0){
				
				return;
			}			
			//更新自己好友数量
			UserSysinfoServiceImpl sysinfoservice = new UserSysinfoServiceImpl();
			UserSysinfoForm sysForm = new UserSysinfoForm();
			
			sysForm.setUserID(theForm.getUserID());
			sysForm.setFirendNum(1);
			sysinfoservice.update(cn, sysForm, msg);
			if(msg.getErrCode() != 0){
				return;
			}
			
			//更新好友的好友数量
			sysForm.clear();
			sysForm.setUserID(theForm.getFriendID());
			sysForm.setFirendNum(1);
			sysinfoservice.update(cn, sysForm, msg);
			if(msg.getErrCode() != 0){
				return;
			}
			
			//添加用户动态表
			OperLogServiceImpl logservice = new OperLogServiceImpl();
			OperLogForm logForm = new OperLogForm();
			
			logForm.setUserID(theForm.getUserID());
			logForm.setType(GlbFinal.OPERTYPE_JIAHAOYOU);				//加好友
			
			String[] arr = new String[7];
			arr[0] = JstlFun.GetUserNick(theForm.getUserID());			//主操作者		
			arr[1] = "和";												//主动者与被动者的关系副词
			arr[2] = String.valueOf(theForm.getFriendID());				//被动接受者ID
			arr[3] =  JstlFun.GetUserNick(theForm.getFriendID());		//被动接受者姓名
			arr[4] = "成为了好友";										//操作
			arr[5] = "";												//操作对象名称
			arr[6] = "";												//操作对象KEY，多个字段以'|'分隔

			logForm.setLogarr(arr);
			
			logservice.add(cn, logForm, msg);
			if(msg.getErrCode() != 0){
				return;
			}	
			

		} catch(Exception ex) 
		{
			common.setAppFailMsg(msg , " 添加好友失败！");
			logger.error("System error , param get about operlog" + ex);
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		}finally {
		}
		
		return ;
	}
	/**
	 * 拉黑好友
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void addblack(FriendForm theForm, ReturnMessage msg) 
	{
		
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			DbcpPool.beginTran(cn);

			delete(cn, theForm, msg);
			if(msg.getErrCode() != 0){
				return;
			}
			
			//计算积分
			JifenServiceImpl jifenservice = new JifenServiceImpl();
			
			jifenservice.compjf(cn, 21, theForm.getFriendID(), msg);
			if(msg.getErrCode() != 0){
				return;
			}			
			
//			//添加到黑名单
//			BlacklistServiceImpl blackservice = new BlacklistServiceImpl();
//			BlacklistForm blackform = new BlacklistForm();
//			
//			blackform.setUserID(theForm.getUserID());
//			blackform.setBlackID(theForm.getFriendID());
//			
//			blackservice.add(cn, blackform, msg);
//			if(msg.getErrCode() != 0){
//				return;
//			}
			
			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);
			DbcpPool.returnConnection(cn);
			return;
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about invite" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return ;
	}
	
	/**
	 * 删除好友记录
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void delete(FriendForm theForm, ReturnMessage msg) 
	{
		
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			DbcpPool.beginTran(cn);

			delete(cn, theForm, msg);
			
			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);
			DbcpPool.returnConnection(cn);
			return;
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about invite" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
			DbcpPool.returnConnection(cn);
		}
		
		return ;
	}

	/**
	 * 删除好友记录
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void delete(Connection cn, FriendForm theForm, ReturnMessage msg) 
	{
		
		try
		{
			//取得FORM中传入的查询参数
			Object[] fields = new Object[4];
			
			fields[0] = theForm.getUserID();
			fields[1] = theForm.getFriendID();
			fields[2] = theForm.getUserID();
			fields[3] = theForm.getFriendID();
			
			FriendServiceSqlMysql servSql = new FriendServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();
			String sql = servSql.getDeleteSql();
								
			boolean  res = bSqlServ.dbWrite(cn, sql, fields);
			if(!res){
				common.setAppFailMsg(msg , " 更新记录失败，请检查！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;
			}
			//更新 好友数量
			UserSysinfoServiceImpl syservice  = new UserSysinfoServiceImpl();
			UserSysinfoForm sysForm = new UserSysinfoForm();

			sysForm.setUserID(theForm.getUserID());

			sysForm.setFirendNum(-1);
			syservice.update(cn, sysForm, msg);
			if(msg.getErrCode() != 0){
				return ;
			}			
			
			sysForm.setUserID(theForm.getFriendID());
			sysForm.setFirendNum(-1);
			syservice.update(cn, sysForm, msg);
			if(msg.getErrCode() != 0){
				return ;
			}				
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about invite" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
		}
		
		return ;
	}	
	/**
	 * 更新一条指定记录
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void updsts(FriendForm theForm, ReturnMessage msg) 
	{
		
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			DbcpPool.beginTran(cn);
			List list = null;

			FriendServiceSqlMysql servSql = new FriendServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();
			
			//取得FORM中传入的查询参数
			Object[] fields = new Object[5];
			
			fields[0] = theForm.getStatus();			
			fields[1] = theForm.getUserID();			
			fields[2] = theForm.getFriendID();			
			fields[3] = theForm.getUserID();			
			fields[4] = theForm.getFriendID();			
			
			String sql = servSql.getUpdstsSql();			
					
			boolean  res = bSqlServ.dbWrite(cn, sql, fields);
			if(!res){
				common.setAppFailMsg(msg , " 更新记录失败，请检查！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;
			}
			
			if(theForm.getStatus().equals(GlbFinal.FRSTS_SHENDU)){
				//添加用户动态表
				OperLogServiceImpl logservice = new OperLogServiceImpl();
				OperLogForm logForm = new OperLogForm();
				
				logForm.setUserID(theForm.getUserID());
				logForm.setType(GlbFinal.OPERTYPE_JIAHAOYOU);					//操作板块：添加好友
				
				String[] arr = new String[7];
				arr[0] = JstlFun.GetUserNick(theForm.getUserID());				//主操作者		
				arr[1] = "和";													//主动者与被动者的关系副词
				arr[2] = String.valueOf(theForm.getFriendID());					//被动接受者ID
				arr[3] = JstlFun.GetUserNick(theForm.getFriendID());			//被动接受者姓名
				arr[4] = " 成为了深度交往好友";									//操作
				arr[5] = " ";													//操作对象名称
				arr[6] = " ";													//
				
				logForm.setLogarr(arr);
				
				logservice.add(cn, logForm, msg);
				if(msg.getErrCode() != 0){
					return;
				}			
				//计算积分
				JifenServiceImpl jifenservice = new JifenServiceImpl();
				
				jifenservice.compjf(cn, 20, theForm.getFriendID(), msg);
				if(msg.getErrCode() != 0){
					return;
				}	
			}
			
			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);
			DbcpPool.returnConnection(cn);
			return;
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about invite" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
			DbcpPool.returnConnection(cn);
		}
				
		return ;
	}
	
	/**
	 * 更新一条指定记录
	 * @see net.IUserbasicService.module.other.IUserService#update(net.swift.common.ReturnMessage)
	 */
	public void update(FriendForm theForm, ReturnMessage msg) 
	{
		
		Connection cn = null;
		try
		{
			cn = DbcpPool.getConnection();
			
			DbcpPool.beginTran(cn);
			List list = null;

			//取得FORM中传入的查询参数
			Object[] fields = new Object[1];
			
			fields[0] = theForm.getSeqID();			
			
			FriendServiceSqlMysql servSql = new FriendServiceSqlMysql();
			BasicSqlService  bSqlServ = new BasicSqlService();
			
			String sql = servSql.getbykeySql();			
					
			list = bSqlServ.dbRead(cn, sql, fields, new DbFriendService());
			
			if(list.size() ==0){
				common.setAppFailMsg(msg , " 取记录失败，请检查！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;				
			}
			
			BaseFriend base = (BaseFriend)list.get(0);
				
			Object[] fields2 = new Object[6];
			
			if(theForm.getUserID() > 0){
				
				fields2[0] = theForm.getUserID();			
			}
			if(theForm.getFriendID() > 0){
				
				fields2[1] = theForm.getFriendID();			
			}
			if(theForm.getTeamID() > 0){
				
				fields2[2] = theForm.getTeamID();			
			}
			if(!theForm.getStatus().equals("")){

				fields2[3] = theForm.getStatus();			
			}
			fields2[4] = DatetimeUtil.getDatetime();			
			fields2[5] = theForm.getSeqID();			
			
			
			sql = servSql.getUpdateSql();			
			
			boolean  res = bSqlServ.dbWrite(cn, sql, fields2);
			if(!res){
				common.setAppFailMsg(msg , " 更新记录失败，请检查！");
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
				return;
			}

			DbcpPool.commitTran(cn);
			DbcpPool.closeTran(cn);
			DbcpPool.returnConnection(cn);
			return;
			
		} catch(Exception ex) 
		{
			logger.error("System error , param get about invite" + ex);
			common.setAppFailMsg(msg , ex.getMessage());
			try 
			{
				DbcpPool.rollBackTran(cn);
				DbcpPool.closeTran(cn);
				DbcpPool.returnConnection(cn);
			} catch(Exception ex1) 
			{
				ex1.printStackTrace();
				logger.error("事务回滚操作失败!ExaServiceImpl->add(01)" , ex1);
			}			
		} finally {
			DbcpPool.returnConnection(cn);
		}
				
		return ;
	}

}
